import QtQuick
import QtQuick.Layouts
import QtCharts

Rectangle {
    Layout.fillWidth: true
    Layout.fillHeight: true

    ChartView {
        id: chartView
        title: "水平百分比柱形图示例"
        titleFont.bold: true
        titleFont.pointSize: 14

        anchors.fill: parent
        antialiasing: true

        BarCategoryAxis {
            id: valueAxisY
            categories: ["6月", "7月", "8月", "9月"]
            titleText: "月份"
        }

        // 无需指定范围
        ValueAxis {
            id: valueAxisX
            titleText: "百分比"
        }

        HorizontalPercentBarSeries {
            name: "柱形图"
            axisX: valueAxisX
            axisY: valueAxisY

            // 设置数值标签可见
            labelsVisible: true

            // 数值标签格式, @value是固定字符串，@value%显示百分比
            labelsFormat: "@value%"
            labelsPosition: AbstractBarSeries.LabelsCenter

            BarSet {
                // 图例名
                label: "bar1"
                color : "#1296FF"

                // 柱形图数值标签
                labelColor: "#333"
                labelFont.family: "Courier"
                labelFont.bold: true
                labelFont.pointSize: 10

                // 边框属性
                borderColor: "#F0F0F0"
                borderWidth: 1

                // 数值
                values: [7, 9, 12, 8]
            }
            BarSet {
                label: "bar2"
                color : "#FF9612"
                labelColor: "#333"
                values: [15, 7, 10, 15]
            }
            BarSet {
                label: "bar3"
                color : "#12FF96"
                labelColor: "#333"
                values: [10, 9, 12, 18]
            }
        }
    }
}
